//
//  LoginViewController.m
//  PopUpDemo
//
//  Created by mac on 2025/9/6.
//
//  登录ViewController

#import "LoginViewController.h"
#import "AppDelegate.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do view setup here.
}

- (IBAction)loginClick:(id)sender {
    // 1.创建聊天界面窗口控制器
    //NSMyWindowController *chatWinControl = [NSMyWindowController windowController];
    
    NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
    NSWindowController *windowController = [storyboard instantiateControllerWithIdentifier:@"MainWindow"];
    NSViewController *mainViewController = [storyboard instantiateControllerWithIdentifier:@"MainVC"];
    windowController.contentViewController = mainViewController;

    // 2.强引用这个Window，不然这个Window会在跳转之后的瞬间被销毁
    AppDelegate *appDelegate = (AppDelegate *)[NSApplication sharedApplication].delegate;
    appDelegate.mainWindowController = windowController;

    // 3.设为KeyWindow并前置
    [windowController.window makeKeyAndOrderFront:self];

    // 4.关闭现在的登录窗口
    [self.view.window orderOut:self];
}

- (IBAction)cancelClick:(id)sender {
    [NSApp terminate:self];
}


@end
